/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package action;

import db.AccountObj;
import db.TransactObj;
import form.TransactForm;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.Transact;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author Administrator
 */
public class TransactAction extends Action {

    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
        TransactForm trans = (TransactForm) form;
        AccountObj objacc = new AccountObj();
        //int result = ;
        if (objacc.CheckAcc(trans.getAccNumber(), trans.getPass())) {
            TransactObj objtran = new TransactObj();
            Transact tran = new Transact();
            tran.setAccountNo(trans.getAccNumber());
            tran.setAmount(trans.getAmount());
            tran.setType(trans.getTransType());
            if (objtran.Transact(tran) > 0) {
                request.setAttribute("items", objtran.List(trans.getAccNumber()));
                return mapping.findForward("ListAll");
            } else {
                request.setAttribute("error", "can't insert Transfer");
                return mapping.findForward("home");
            }
        } else {
            request.setAttribute("error", "db don't have this record");
            return mapping.findForward("home");
        }

    }
}
